<?php
defined('JOC') or die;
/**
 * Description of request
 *
 * @author jcamelis
 */
class request {
  
  private $_post = Array();
  private $_get  = Array();
  function __construct()
  {
    /* 
     * includes R.class.php 
     * this allow R to be called in static way ;
     */
    require_once(ROOT.'/core/request/R.class.php');
    
    /*
     * Save a copy of $_GET , $_POST , $_SERVER 
     */
    $this->_post    = $_POST ;
    $this->_get     = $_GET  ;
    $this->_server  = $_SERVER  ;
    
    $this->process_server();
  }
  function get( $index = '' )
  {
    return $index != '' && isset($this->_get[$index]) ? $this->_get[$index] : false ;
  }
  function post( $index = '' )
  {
    return $index != '' && isset($this->_post[$index]) ? $this->_post[$index] : false ;
  }
  function server( $index = '' )
  {
    return $index != '' && isset($this->_server[$index]) ? $this->_server[$index] : false ;
  }
  function all( $index = '' )
  {
//  	debug::pr($index);

//  	debug::pr($this->server($index) ? $this->server($index) : ( $this->get($index) ? $this->get($index) : $this->post($index) ));
    return $this->server($index) ? $this->server($index) : ( $this->get($index) ? $this->get($index) : $this->post($index) ) ;
  }
  /*
   * This Method simulates the Friendly URL
   * as index.php is Single Point of Access 
   * we manipulate $_SERVER['REQUEST_URI'] to obtain the request of the client ;
   */
  function process_server()
  {
    $this->_server['uri'] = $this->server('REQUEST_URI') ? explode('/',$this->server('REQUEST_URI')) : Array() ;
    if($this->_server['uri'][0] == SITE_FOLDER && count($this->_server['uri']) > 1 )
    {
    	$this->_server['uri'] = array_slice($this->_server['uri'],1) ;
    }
    
//    debug::pr($this->_server['uri'],'',true) ;
    
    if(isset($this->_server['uri'][0]))
    {
    	$this->_server['page'] = $this->_server['uri'][0] ;
    } 
  }
}
